<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        // 后面的数据库查询代码都放在这个位置
        // 插入记录
        $result = Db::execute('insert into think_data (id, name ,status) values (5, "thinkphp",1)');
        dump($result);

        // 更新记录
        $result = Db::execute('update think_data set name = "framework" where id = 5 ');
        dump($result);

        // 查询数据
        $result = Db::query('select * from think_data where id = 5');
        dump($result);

        // 删除数据
        $result = Db::execute('delete from think_data where id = 5 ');
        dump($result);

        // 显示数据库列表
        $result = Db::query('show tables from demo');
        dump($result);

        // 清空数据表
        $result = Db::execute('TRUNCATE table think_data');
        dump($result);

    }

    public function hello($name = 'World' , $city = '')
    {
        echo 'url: ' . $this->request->url(). '<br/>';
        return 'Hello,' . $name . '! You come from ' .$city . '.';
    }

    public function test()
    {
        return '这是一个测试方法！';
    }

    protected function hello2()
    {
        return '只是protected方法！';
    }

    private function hello3()
    {
        return '这是private方法！';
    }
}
